<html lang="en">
<head>
    <title>攻略文章管理</title>
    <#include "../common/header.ftl">
    <script type="text/javascript" src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script type="text/javascript" src="/js/ckeditor/ckeditor/ckeditor.js"></script>
    <script>
        $(function () {
            //富文本框编辑器
            var ck = CKEDITOR.replace('content',{
                filebrowserBrowseUrl:'/装作有服务器',
                filebrowserUploadUrl:'/images/upload.do'
            });

            $(".editStrategyDetailBtn").click(function () {
                //重置表单
                $("#editForm")[0].reset();
                var json = $(this).data("json");
                if(json) {
                    $("#editForm input[name='id']").val(json.id)
                    $("#editForm input[name='title']").val(json.title)
                    $("#editForm input[name='releaseTime']").val(json.releaseTime)
                    $("#editForm input[name='coverUrl']").val(json.coverUrl)
                    $("#coverUrl").attr("src",json.coverUrl);
                    $("#editForm input[name='sequence']").val(json.sequence)
                    $("#editForm select[name='state']").val(json.state)
                    //大攻略的回显
                    $("#editForm select[name='strategy.id']").val(json.strategyId);

                    //目录的查询
                    $.get('/strategyCatalog/getCatalogByStrategyId.do',{strategyId:json.strategyId},function (data) {
                        var html = "<option value='-1'>--请选择--</option>";
                        $.each(data,function (index, item) {
                            html+="<option value='"+item.id+"'>"+item.name+"</option>"
                        })
                        $("#strategyCatalogSelect").html(html);
                        //目录的回显
                        $("#editForm select[name='catalog.id']").val(json.catalogId)
                    })
                    //内容的回显,因为内容传输太大,所有通过查询,而不通过json查询
                    $.get("/strategyDetail/getContentByStrategyDetailId.do",{detailId:json.id},function (data) {
                        ck.setData(data.content);
                    })
                }

                $("#editModal").modal("show");
            });
            //保存操作
            $(".saveBtn").click(function () {

                var content = ck.getData();
                $("#content").html(content);
                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        window.location.reload();
                    }else {
                        window.messager.alert("温馨提示",data.msg)
                    }
                })
            });



            $('#strategySelect').change(function () {

                var strategyId = $(this).val();
                if(strategyId==-1){
                    $("#strategyCatalogSelect").html("<option value='-1'>--请选择--</option>");
                    return;
                }
                $.get('/strategyCatalog/getCatalogByStrategyId.do',{strategyId:strategyId},function (data) {
                    var html = "<option value='-1'>--请选择--</option>";
                     $.each(data,function (index, item) {
                         html+="<option value='"+item.id+"'>"+item.name+"</option>"
                     })
                     $("#strategyCatalogSelect").html(html);

                })
            })

           
        })

    </script>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="strategyDetail">
<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略文章管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyDetail/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}" placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <a id="btn_query" class="btn btn-info editStrategyDetailBtn"><span class="glyphicon glyphicon-search"></span>添加攻略文章</a>


            </form>
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>标题</th>
                    <th>封面</th>
                    <th>发布时间</th>
                    <th>排序</th>
                    <th>攻略类别</th>
                    <th>状态</th>
                    <th>编辑</th>
                </tr>
                </thead>
               <#list result.list as entity >
                     <tr>
                         <td>${(entity.title)!}</td>
                         <td><img src="${(entity.coverUrl)!}" width="50px"></td>
                         <td>${(entity.releaseTime?string("yyyy-MM-dd"))!}</td>
                         <td>${entity.sequence!}</td>
                         <td>${(entity.catalog.name)!}</td>
                         <td>${entity.stateDisplay!}</td>
                         <td>

                             <a href="javascript:;" class="btn editStrategyDetailBtn" data-json='${entity.jsonString}'>修改</a>
                         </td>
                     </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<#--攻略文章编辑模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> </button>
                <h4 class="modal-title">攻略文章编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyDetail/saveOrUpdate.do" method="post" enctype="multipart/form-data" id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title" value="" placeholder="请输入标题名称">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="200px;">

                            <input type="file" id="fileId" name="file">
                        <#--如果上面的file没有选中,会为空值,updata时,还会 更新,
                            解决
                        -->
                            <input type="hidden" name="coverUrl">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">所属攻略：</label>
                        <div class="col-sm-6">
                            <select name="strategy.id" id="strategySelect" class="form-control">
                                <option value="-1">--请选择--</option>
                                <#list strategys as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">所属类别：</label>
                        <div class="col-sm-6">
                            <select id="strategyCatalogSelect" name="catalog.id" class="form-control">
                                <option value="-1">--请选择--</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">是否发布：</label>
                        <div class="col-sm-6">
                            <select name="state" class="form-control">
                                <option value="-1">--请选择--</option>
                                <option value="0">--否--</option>
                                <option value="1">--是--</option>
                            </select>
                        </div>
                    </div>
                    <#--富文本编辑框-->
                    <textarea name="strategyContent.content" id="content" rows="10" cols="80">

                    </textarea>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">排序：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control" name="sequence" value="">
                        </div>
                    </div>
                </form>
            </div>

            <div class="modal-footer">
                <button type="submit" class="btn btn-primary saveBtn" >保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
